import request from '@/utils/request'

export function getScoreList(params) {
  return request.get('/grade', { params })
}

export function updateScore(params) {
    return request.put('/grade', params, {
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    })
  }

export function deleteScore(studentId, courseId) {
  return request.delete('/grade', { params: { studentId, courseId } })
}

export function getCoursesByTeacherId(teacherId) {
    return request.get(`/course/teacher/${teacherId}`)
  }

  export function addScore(data) {
    const params = new URLSearchParams()
    params.append('courseId', data.courseId)
    params.append('studentId', data.studentId)
    params.append('usualScore', data.usualScore)
    params.append('examScore', data.examScore)
    return request.post('/grade', params, {
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    })
  }

  // 根据课程ID获取学生列表
export function getStudentsByCourseId(courseId) {
    return request.get(`/student/analysis/students/${courseId}`)
  }

export function getScoreAvg(params) {
  return request.get('/grade/avg', { params })
}

export function getScoreLevel(params) {
  return request.get('/grade/level', { params })
}
  
  